package com.cskaoyan.bean.Exception;

import com.cskaoyan.bean.BaseRespVo;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 创建日期: 2022/05/10 10:14
 *
 * @author 孙豪骏
 */




//public class CustomControllerAdvice {
//    @ExceptionHandler(IncorrectCredentialsException.class)
//    public ExceptionInfo handleArithmeticException(IncorrectCredentialsException exception) {//形参中可以直接获得抛出的异常
//        ExceptionInfo exceptionInfo = new ExceptionInfo();
//        exceptionInfo.setNo(500);
//        exceptionInfo.setMessage(exception.getMessage());
//        return exceptionInfo;
//    }
//}

@RestControllerAdvice
public class CustomControllerAdvice {
    @ExceptionHandler(IncorrectCredentialsException.class)
    public BaseRespVo handleArithmeticException(IncorrectCredentialsException exception) {//形参中可以直接获得抛出的异常


        return BaseRespVo.getResult(null,"你的账号密码不对",605);
    }

    @ExceptionHandler(AuthorizationException.class)
    public BaseRespVo handleAuthorizationException(AuthorizationException exception) {//形参中可以直接获得抛出的异常

        return BaseRespVo.getResult(null,"没有权限算了吧",605);
    }
    @ExceptionHandler(IllegalStateException.class)
    public ExceptionInfo handleAuthorizationException2(IllegalStateException exception) {//形参中可以直接获得抛出的异常

        return new ExceptionInfo(404,"没有权限做授权，看看就好了");
    }
}